package com.kwin;

import redis.clients.jedis.Jedis;

import java.util.List;

public class TestList {
    public static void main(String[] args) {
        Jedis jedis = new Jedis("127.0.0.1", 6379);
        jedis.flushDB();
        System.out.println("===============添加一个List===============");
        jedis.lpush("List","H","A","B","C","D","E");
        jedis.lpush("List","H","F","G");
        jedis.lpush("List","H");
        System.out.println("List:" + jedis.lrange("List", 0, -1));
        System.out.println("List区间0-3的元素:" + jedis.lrange("List",0,3));

        System.out.println("=========================================");
        System.out.println("删除指定元素个数：" + jedis.lrem("List", 2, "H"));
        System.out.println("List:" + jedis.lrange("List",0,-1));
        System.out.println("删除下标0-3之外的元素:" + jedis.ltrim("List",0,3));
        System.out.println("List:" + jedis.lrange("List",0,-1));
        System.out.println("List列表出栈(左端):" + jedis.lpop("List"));
        System.out.println("List:" + jedis.lrange("List",0,-1));
        System.out.println("List添加元素，从列表右端:" + jedis.rpush("List", "I"));
        System.out.println("List:" + jedis.lrange("List",0,-1));
        System.out.println("List列表出栈(右端):" + jedis.rpop("List"));
        System.out.println("List:" + jedis.lrange("List",0,-1));
        System.out.println("修改List指定下标1的内容:" + jedis.lset("List", 1, "kwin"));
        System.out.println("List:" + jedis.lrange("List",0,-1));

        System.out.println("=========================================");
        System.out.println("List的长度:" + jedis.llen("List"));
        System.out.println("获取List下标为2的元素:" + jedis.lindex("List", 2));

        System.out.println("=========================================");
        jedis.lpush("sortedList", "5", "1", "2", "3", "6");
        System.out.println("sortedList排序前:" + jedis.lrange("sortedList",0,-1));
        List<String> sortedList = jedis.sort("sortedList");
        System.out.println(sortedList);
        System.out.println("sortedList排序后:" + jedis.lrange("sortedList",0,-1));
    }
}
